'use strict';

const USER = require('../../class/User');

module.exports = {
  post: {
    'login': {
      des: {
        params: [
          { key: 'openid' }
        ]
      },
      method: (req, res, next) => {

        let data = req.body;
        let key = data.session;
        delete data.session;


        new USER(data).save().then(user => {
          console.log('user login,', user);
          client.setex(key, 7200, JSON.stringify(user), function(err) {
            if (err) return next(err);

            res.json(user);
          });
        }).catch(e => next(e));
      }
    }
  }
};
